var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        });
Object.defineProperty(i, "__esModule", {value: !0});
var r = (function (e) {
    function t() {
        var t = (null !== e && e.apply(this, arguments)) || this;
        return (
            (t._loading_fictitious_prog = 0),
            (t._loading_fictitious_prog_speed = 0.03),
            (t._loading_actual_prog = 0),
            (t._is_loading_success = !1),
            (t._assetsModules = []),
            (t._successCallBack = null),
            (t._failCallBack = null),
            (t._timer = -1),
            t
        );
    }
    return (
        a(t, e),
        (t.prototype.execute = function (e) {
            var t = e.getBody();
            t &&
                (t.failCallBack && (this._failCallBack = t.failCallBack),
                t.finishCallBack && (this._successCallBack = t.finishCallBack),
                t.assetsModules && (this._assetsModules = t.assetsModules)),
                this.startLoadRes();
        }),
        (t.prototype.resetParam = function () {
            (this._loading_fictitious_prog = 0), (this._loading_actual_prog = 0), (this._is_loading_success = !1);
        }),
        (t.prototype.startLoadRes = function () {
            var e = this;
            if (
                (game.log("LoadResCommand", "startLoadingRes  " + JSON.stringify(this._assetsModules)),
                this.resetParam(),
                this.clearTimer(),
                this._assetsModules)
            ) {
                var t = this._assetsModules,
                    o = game.AssetsManager.instance.getNeedLoadAssetsBundleNames(t);
                o.length > 0
                    ? ((this._timer = setInterval(this.checkLoadingProgress.bind(this), 10)),
                      game.AssetsManager.instance.reloadBundleAssetss(
                          o,
                          function () {
                              (e._is_loading_success = !0), (e._loading_actual_prog = 1);
                          },
                          this.onLoadingResourceFail.bind(this),
                          this.onLoadingResourceProgress.bind(this)
                      ))
                    : this.onLoadingResourceSuccess();
            }
        }),
        (t.prototype.clearTimer = function () {
            this._timer && (clearInterval(this._timer), (this._timer = -1));
        }),
        (t.prototype.checkLoadingProgress = function () {
            var e = this._loading_fictitious_prog;
            e + this._loading_fictitious_prog_speed <= this._loading_actual_prog
                ? (e += this._loading_fictitious_prog_speed)
                : 1 - this._loading_actual_prog <= this._loading_fictitious_prog_speed && (e = 1),
                e != this._loading_fictitious_prog &&
                    ((this._loading_fictitious_prog = e), this.refreshLoadingProgress(this._loading_fictitious_prog)),
                this._loading_fictitious_prog >= 1 && this._is_loading_success && this.onLoadingResourceSuccess();
        }),
        (t.prototype.refreshLoadingProgress = function (e) {
            this.sendNotification(t.LOAD_RES_PROGRESS, {progress: e});
        }),
        (t.prototype.onLoadingResourceProgress = function (e) {
            this._loading_actual_prog = e;
        }),
        (t.prototype.onLoadingResourceSuccess = function () {
            this.clearTimer(), this._successCallBack && this._successCallBack();
        }),
        (t.prototype.onLoadingResourceFail = function (e) {
            game.error("LoadResCommand", "loadingAssets error" + e),
                this.clearTimer(),
                this._failCallBack &&
                    this._failCallBack({
                        error_code: game.LoadingAssetsErrorCode.LoadingResourceError,
                        error_msg: "资源加载失败"
                    });
        }),
        (t.LOAD_RES_PROGRESS = "LOAD_RES_PROGRESS"),
        t
    );
})(puremvc.SimpleCommand);
i.default = r;
